<?php
// +----------------------------------------------------------------------
// | KITEGO-Admin「开箱即用」「人人全栈」
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2024 https://www.kitego.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed KITEGO并不是自由软件，未经许可不能去掉KITEGO相关版权
// +----------------------------------------------------------------------
// | Author: KITEGO Team <bd@kitego.cn>
// +----------------------------------------------------------------------

namespace kitego\extend\storage\impl;

use kitego\extend\storage\Storage;
use kitego\services\common\FileService;
use Qcloud\Cos\Client;

class QCloudImpl extends Storage
{
    protected $client;
    protected $config;

    public function __construct($config)
    {
        $this->config = $config;

        $this->client = new Client(
            [
                'region' => $config['qcloud_region'],
                'credentials' => [
                    'appId' => $config['qcloud_app_id'],
                    'secretId' => $config['qcloud_secret_id'],
                    'secretKey' => $config['qcloud_secret_key']
                ]
            ]
        );
    }

    /**
     * 上传
     */
    public function upload($path)
    {
        // Max 5G
        $this->client->putObject([
            'Bucket' => $this->config['qcloud_bucket'],
            'Key' => $path . '/' . $this->fileName,
            'Body' => fopen($this->fileInfo['realPath'], 'rb')
        ]);

        return true;
    }

    /**
     * 删除
     */
    public function delete($path)
    {
        $this->client->deleteObject([
            'Bucket' => $this->config['qcloud_bucket'],
            'Key' => $path
        ]);

        return true;
    }

    public function water($path)
    {
        // TODO: Implement water() method.
    }
}